package middleware

import (
	"gitee.com/Luna-CY/Golang-Project-Template/internal/context/contextutil"
	"gitee.com/Luna-CY/Golang-Project-Template/internal/logger"
	"github.com/gin-gonic/gin"
)

func CustomGinRecovery() gin.HandlerFunc {
	return gin.CustomRecovery(func(c *gin.Context, err any) {
		logger.SugarLogger(logger.WithRequestId(contextutil.NewContextWithGin(c)), logger.WithStack()).Errorf("gin recover: %v", err)

		c.AbortWithStatusJSON(500, gin.H{
			"code": 500,
			"msg":  "InternalServerError",
		})
	})
}
